package com.qianfeng;

public class NumToName {
    private NumToName() {
    }

    private static final NumToName numToName = new NumToName();

    public static NumToName getInstance() {
        return numToName;
    }
    //传入数组，转化为对应字符串
    String getName(int num,int splitNum){
        int[] ints = splitByNum(num, splitNum);
        StringBuilder str = new StringBuilder();
        for (int anInt : ints) {
            str.append((char) anInt);
        }
        return str.toString();
    }
    //分割一串数字，参数为两个数字，第一个是要分割的数字对象，第二个是以多少个为一组
    int[] splitByNum(int num, int splitNum) {
        String s = String.valueOf(num);
        int[] spl;
        int length = s.length();
        int shang = length / splitNum;
        int yu = length % splitNum;
        if (yu != 0) {
            spl = new int[shang + 1];
        } else {
            spl = new int[shang];
        }
        for (int i = 0; i < spl.length; i++) {
            spl[i] = Integer.parseInt(s.substring(i * splitNum, (i + 1) * splitNum));
        }
        return spl;
    }
    String confess(int num, int splitNum){
        String s = getName(num, splitNum);
        return "lov-"+s;
    }
}
